﻿using MessagePack;

public interface IResponse
{
    int ErrorCode { get; set; }
}

[MessagePackObject(true)]
public abstract class Message
{
    /// <summary>
    /// 路由 消息类型id
    /// </summary>
    [IgnoreMember]
    public abstract int Route { get; }

    /// <summary>
    /// 兼容客户端引用对象的清理接口
    /// </summary>
    public virtual void OnRecycle()
    {
    }
}

[MessagePackObject(true)]
public abstract class RequestMessage : Message
{
    /// <summary>
    /// 消息唯一id
    /// </summary>
    public uint RpcId { get; set; }

    public override void OnRecycle()
    {
        base.OnRecycle();
        RpcId = 0;
    }
}

[MessagePackObject(true)]
public abstract class ResponseMessage : Message, IResponse
{
    /// <summary>
    /// 消息唯一id
    /// </summary>
    public uint RpcId { get; set; }
    
    /// <summary>
    /// 错误码
    /// </summary>
    public int ErrorCode { get; set; }
    
    public override void OnRecycle()
    {
        base.OnRecycle();
        RpcId = 0;
        ErrorCode = 0;
    }
}